namespace EFS.RC.CC.SAL.Writers
{
	internal class DB
	{
		// synk access
		private System.Object syncAccess = new System.Object();

		// DB Connection
		private EFS.DB.Connection connection = null;

		/// Property Instance (singleton): Get
		public static DB Instance { get; private set; }

		/// <summary>
		/// Static constructor to init local instance
		/// </summary>
		static DB()
		{
			Instance = new DB();
		}

		/// <summary>
		/// Contructor
		/// </summary>
		private DB()
		{
			connection = EFS.RC.CC.SA.Connection.New;
		}

   		// Log entry
		public void Write(EFS.RC.CC.SAL.Loggers.Messages.Message message)
		{
			// ~ commented for performance ~  EFS.EventLog.Log.LogExtended("Entering lock", new System.Diagnostics.StackTrace());
			lock (syncAccess)
			{
				try
				{
					// create into DB
					EFS.RC.CC.SA.Tables.ServerActivity.Create(
						message.Occurred,
						message.ConversationGuid,
						message.Method,
						message.Detail,
						message.Context,
						connection);
				}
				catch (System.Exception ex)
				{
					EFS.EventLog.Log.LogException(ex, null);
				}
			}
		}
	}

}